import { ref } from 'vue'
import { AllMenuPermission, PermissionRender } from './types'

const useGetPermissionRender = () => {
  const permissionRender = ref<Array<Array<PermissionRender>>>([])
  const setPermissionRender = (permissions: Array<AllMenuPermission>) => {
    permissions.forEach((permission) => {
      let permissionLevel = 0
      const map = (permissions: Array<AllMenuPermission>) => {
        permissions.forEach((permission) => {
          if (permission.authorVos.length >= 1) {
            permissionLevel += 1
            map(permission.authorVos)
          }
        })
      }
      if (permission.authorVos.length >= 1) {
        permissionLevel += 1
        map(permission.authorVos)
      }
    })
  }

  return {
    permissionRender,
    setPermissionRender,
  }
}

export default useGetPermissionRender
